/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beanControl;

import beanCRUD.FlightFacadeLocal;
import beanInfo.Flight;
import helper.messageUtil;
import helper.sessionTool;
import java.util.List;
import javax.ejb.EJB;

/**
 *
 * @author VANTRUY
 */
public class FlightControl {

    @EJB
    private FlightFacadeLocal flightFacade;
    private Flight f = new Flight();
    private int error = 1;

    public int getError() {
        return error;
    }

    public void setError(int error) {
        this.error = error;
    }

    public Flight getF() {
        return f;
    }

    public void setF(Flight f) {
        this.f = f;
    }

    public List<Flight> getListFlight() {
        return flightFacade.findAll();
    }

    public void insertFlight() {
        this.flightFacade.create(f);
        messageUtil.msgInfor("Add new flight with name :" + this.f.getFlightName() + " successfully ");
        this.error = 0;
    }

    public void setSessionUp() {
        sessionTool.setSession("flightID", this.f.getFlightID());
    }

    public void updateFlight() {
        this.f.setFlightID(Integer.parseInt(sessionTool.getSession("flightID").toString()));
        sessionTool.removeSession("flightID");
        this.flightFacade.edit(f);
        messageUtil.msgInfor("Update course" + this.f.getFlightName() + "successfull !");
        this.error = 0;
    }

    public void setSessionDel() {
        sessionTool.setSession("flightID", this.f.getFlightID());
    }

     public void deleteFlight() {
            this.f.setFlightID(Integer.parseInt(sessionTool.getSession("flightID").toString()));
            sessionTool.removeSession("flightID");
            this.flightFacade.remove(f);
            messageUtil.msgInfor("Delete flight successfully !");
            this.error = 0;

        }

    /** Creates a new instance of FlightControl */
    public FlightControl() {
    }
}
